package com.zh.note.demo.javaSE;

import lombok.Getter;
import lombok.Setter;

/**
 * @Author: zhanghuan
 * @date: 2025/8/23 23:06
 * @description: create it
 * <p>
 * 传值还是传引用
 */
public class TransmitValueOrRef {

    public void changeValue1(int age) {
        age = 30;
    }

    public void changeValue2(Person person) {
        person.setPersonName("xxx");
    }

    public void changeValue3(String str) {
        str = "xxx";
    }


    public static void main(String[] args) {
        TransmitValueOrRef test = new TransmitValueOrRef();
        int age = 20;
        test.changeValue1(age);
        System.out.println("age-->" + age);

        Person person = new Person("abc");
        test.changeValue2(person);
        System.out.println("personName-->" + person.getPersonName());

        String str = "abc";
        test.changeValue3(str);
        System.out.println("String-->" + str);
    }

    @Setter
    @Getter
    static class Person {
        private Integer id;
        private String personName;

        public Person(String personName) {
            this.personName = personName;
        }
    }


}

